<?php
defined( '_JEXEC' ) or die( 'Restricted access' );
//print_r($this->product);exit();
$editor = &JFactory::getEditor();
JFilterOutput::objectHTMLSafe( $this->item );
JHTML::_('behavior.calendar');
JHTML::_('behavior.modal', 'a.modal');
$document	=& JFactory::getDocument();
$link = JRoute::_( 'index.php?option=com_ecommerce&controller=registers&task=delete_img&id='. $this->product->id );
$link1 = JRoute::_( 'index.php?option=com_ecommerce&controller=registers&task=delete_img1' );
//print_r($this->product);exit();
$item = $this->product;
?>
<style>
table.admintable td.key{
	width:120px;
}
</style>
<script language="javascript">
function submitbutton(pressbutton){

	var form = document.adminForm;
	if (pressbutton == 'cancel') {
		submitform( pressbutton );
		return;
	}
	
			
	// do field validation
	if (form.model.value == ""){
		alert( "Please enter product model" );
	} else if(form.type.value == 0){
		alert( "Please select product type" );
	} else if(form.name.value == ''){
		alert( "Please enter name" );
		form.name.focus();
	} else if(form.email.value == ''){
		alert( "Please enter email" );
		form.email.focus();
	} else if(form.address.value == ''){
		alert( "Please enter address" );
		form.address.focus();
	} else if(form.code.value == ''){
		alert( "Please enter post code" );
		form.code.focus();
	} else if(form.city.value == ''){
		alert( "Please enter city" );
		form.city.focus();
	} else {
		submitform( pressbutton );
	}
	
}
</script>
<script type="text/javascript" src="../templates/tpl_automobil/js/jquery.json-2.2.min.js"></script>
<script type="text/javascript">
jQuery(document).ready(function(){
	loadData = function(emailAdd){
		jQuery.ajax({
			type: 'POST',
			url: ('../index.php?option=com_ecommerce&task=loadUserData'),
			data: {email: emailAdd},
			success: function(result){
				result=jQuery.evalJSON(result);
				if(result.status == 1){
					jQuery('#name').val(result.name);
					jQuery('#company').val(result.company);
					jQuery('#cvr').val(result.cvr);
					jQuery('#address').val(result.address);
					jQuery('#code').val(result.code);
					jQuery('#city').val(result.city);
					jQuery('#phone').val(result.phone);
					jQuery('#user_id').val(result.userid);
				}
			},
			dataType: 'JSON'
		});
	}
	jQuery('.moreUpload').click(function(e) {
        var num = jQuery('#imageNum').val();
		stt = parseInt(num) + 5;
		html = '<tr><td align="right" class="key">Product image '+stt+':</td><td><input type="hidden" value="" name="imageold'+num+'"></td></tr><tr><td align="right" class="key"><label for="imagefile"> Upload Image '+stt+': </label></td><td><input type="file" value="" size="32" id="imageadd'+num+'" name="imageadd'+num+'"></td></tr>';
		jQuery('#imageNum').before(html);
		jQuery('#imageNum').val(parseInt(num)+1);
    });
});
</script>
<form action="index.php" method="post" name="adminForm" id="adminForm" enctype="multipart/form-data">
  <div class="col100">
  <fieldset class="adminform">
  <legend><?php echo JText::_( 'Specifikationer' ); ?></legend>
  <table class="admintable" style="float:left;">
  	<tr>
      <td align="right" class="key"><label for="title_on_link"><?php echo JText::_( 'Kat No' ); ?>: </label>
      </td>
      <td><input class="text_area" type="text" name="katno" id="katno" size="20" maxlength="250" value="<?php echo htmlspecialchars($this->product->katno);?>" />
      </td>
    </tr>
    <tr>
      <td align="right" class="key"><label for="title_on_link"><?php echo JText::_( 'Model' ); ?>:* </label>
      </td>
      <td><input class="text_area" type="text" name="model" id="model" size="50" maxlength="250" value="<?php echo htmlspecialchars($this->product->model);?>" />
      </td>
    </tr>
     <tr>
      <td align="right" class="key"><label for="title_on_link"><?php echo JText::_( 'Placering' ); ?>: </label>
      </td>
      <td><input class="text_area" type="text" name="placering" id="placering" size="50" maxlength="250" value="<?php echo htmlspecialchars($this->product->placering);?>" />
      </td>
    </tr>
    <tr>
      <td align="right" class="key"><label for="desc_on_link"> <?php echo JText::_( 'Type' ); ?>:* </label>
      </td>
      <td>
      	<select name="type" id="type">
        	<option value="0">--Select type--</option>
            <option value="1" <?php if($this->product->type == 1) echo 'selected="selected"';?> >Catalogue</option>
            <option value="2" <?php if($this->product->type == 2) echo 'selected="selected"';?> >Cars for sale</option>
            <option value="3" <?php if($this->product->type == 3) echo 'selected="selected"';?> >Upcoming auction</option>
        </select>
      </td>
    </tr>
    
    <tr>
      <td align="right" class="key"><label for="code bar"> <?php echo JText::_( '1st Reg.' ); ?>: </label>
      </td>
      <td>
      	<?php echo JHTML::_('calendar', $this->product->register_day, 'register_day', 'register_day', '%d-%m-%Y', array('class'=>'inputbox', 'size'=>'32',  'maxlength'=>'32')); ?>
      </td>
    </tr>
     <tr>
      <td align="right" class="key"><label for="code bar"> <?php echo JText::_( 'Seneste syn' ); ?>: </label>
      </td>
      <td>
      <?php echo JHTML::_('calendar', $this->product->view_day, 'view_day', 'view_day', '%d-%m-%Y', array('class'=>'inputbox', 'size'=>'32',  'maxlength'=>'32')); ?>
      </td>
    </tr>
    <tr>
      <td align="right" class="key"><label for="code bar"> <?php echo JText::_( 'Tilmelding af bilen Biltype' ); ?>: </label>
      </td>
      <td>
      <select name="car_type" id="car_type">
            <option value="Personbil" <?php if($this->product->car_type == 'Personbil') echo 'selected="selected"';?> >Personbil</option>
            <option value="Varevogn momsfri" <?php if($this->product->car_type == 'Varevogn momsfri') echo 'selected="selected"';?> >Varevogn momsfri</option>
            <option value="Varevogn + moms" <?php if($this->product->car_type == 'Varevogn + moms') echo 'selected="selected"';?> >Varevogn + moms</option>
        </select>
      </td>
    </tr>
    <tr>
      <td align="right" class="key"><label for="code bar"> <?php echo JText::_( 'Brændstof' ); ?>: </label>
      </td>
      <td>
      <select name="fuel" id="fuel">
            <option value="Benzin" <?php if($this->product->fuel == 'Benzin') echo 'selected="selected"';?> >Benzin</option>
            <option value="Diesel" <?php if($this->product->fuel == 'Diesel') echo 'selected="selected"';?> >Diesel</option>
        </select>
      </td>
    </tr>
    <tr>
      <td align="right" class="key"><label for="code bar"> <?php echo JText::_( 'Skal synes' ); ?>: </label>
      </td>
      <td>
      		<select name="registry" id="registry">
            <option value="0" <?php if($this->product->registry == 0) echo 'selected="selected"';?>>No</option>
            <option value="1" <?php if($this->product->registry == 1) echo 'selected="selected"';?>>Yes</option>
            </select>
      </td>
    </tr>
    <tr>
      <td align="right" class="key"><label for="code bar"> <?php echo JText::_( 'Stand/Kategori' ); ?>: </label>
      </td>
      <td>
      	<select name="stand">
        <option value="A" <?php if($this->product->stand == 'A') echo 'selected="selected"';?>>A</option>
        <option value="B" <?php if($this->product->stand == 'B') echo 'selected="selected"';?>>B</option>
        <option value="UK" <?php if($this->product->stand == 'UK') echo 'selected="selected"';?>>UK</option>
        </select>
      </td>
    </tr>
    <tr>
      <td align="right" class="key"><label for="code bar"> <?php echo JText::_( 'Km.stand' ); ?>: </label>
      </td>
      <td><input class="text_area" type="text" name="km" id="km" size="20" maxlength="250" value="<?php echo $this->product->km;?>" />
      </td>
    </tr>
    <tr>
      <td align="right" class="key"><label for="code bar"> <?php echo JText::_( 'Registeringsnummer' ); ?>: </label>
      </td>
      <td><input class="text_area" type="text" name="carid" id="carid" size="50" maxlength="250" value="<?php echo $this->product->carid;?>" />
      </td>
    </tr>
     <tr>
      <td align="right" class="key"><label for="code bar"> <?php echo JText::_( 'Video' ); ?>: </label>
      </td>
      <td><input class="text_area" type="text" name="video" id="video" size="50" maxlength="250" value="<?php echo $this->product->video ;?>" />
      </td>
    </tr>
    <tr>
      <td align="right" class="key"><label for="code bar"> <?php echo JText::_( 'Farve' ); ?>: </label>
      </td>
      <td><input class="text_area" type="text" name="color" id="color" size="50" maxlength="250" value="<?php echo $this->product->color;?>" />
      </td>
    </tr>
    <!--<tr>
      <td align="right" class="key"><label for="code bar"> <?php echo JText::_( 'Lakstand' ); ?>: </label>
      </td>
      <td><input class="text_area" type="text" name="color_type" id="color_type" size="50" maxlength="250" value="<?php echo $this->product->color_type;?>" />
      </td>
    </tr>
    <tr>
      <td align="right" class="key"><label for="code bar"> <?php echo JText::_( 'Kabinefarve' ); ?>: </label>
      </td>
      <td><input class="text_area" type="text" name="cabin_color" id="cabin_color" size="50" maxlength="250" value="<?php echo $this->product->cabin_color;?>" />
      </td>
    </tr>-->
    <tr>
      <td align="right" class="key"><label for="code bar"> <?php echo JText::_( 'Stelnummer' ); ?>: </label>
      </td>
      <td><input class="text_area" type="text" name="chassis" id="chassis" size="50" maxlength="250" value="<?php echo $this->product->chassis;?>" />
      </td>
    </tr>
    <tr>
      <td align="right" class="key"><label for="code bar"> <?php echo JText::_( 'Hammerslagpris ' ); ?>: </label>
      </td>
      <td><input class="text_area" type="text" name="desired_price" id="desired_price" size="50" maxlength="250" value="<?php echo $this->product->desired_price;?>" /> DKK
      </td>
    </tr>
    <tr>
      <td align="right" class="key"><label for="desc_on_link">Information: </label>
      </td>
      <td width="550"><textarea name="comment" rows="5" cols="55"><?php echo $this->product->comment; ?></textarea> </td>
    </tr>
  </table>
  
  
  
  <table class="admintable">
  	<tr>
      <td align="left" colspan="2"><strong>User information:</strong></td>
    </tr>
	<tr>
      <td align="right" class="key"><label for="title_on_link"><?php echo JText::_( 'Name' ); ?>:* </label>
      </td>
      <td><input class="text_area" type="text" name="name" id="name" size="50" maxlength="250" value="<?php echo htmlspecialchars($this->user->name);?>" <?php if($this->product->id) echo 'readonly="readonly"';?> />
      </td>
    </tr>
    <tr>
      <td align="right" class="key"><label for="title_on_link"><?php echo JText::_( 'Email' ); ?>:* </label>
      </td>
      <td><input class="text_area" type="text" name="email" id="email" size="50" maxlength="250" value="<?php echo htmlspecialchars($this->user->email);?>" onblur="loadData(this.value);" <?php if($this->product->id) echo 'readonly="readonly"';?> />
      </td>
    </tr>
     <tr>
      <td align="right" class="key"><label for="title_on_link"><?php echo JText::_( 'Company' ); ?>: </label>
      </td>
      <td><input class="text_area" type="text" name="company" id="company" size="50" maxlength="250" value="<?php echo htmlspecialchars($this->user->company);?>" <?php if($this->product->id) echo 'readonly="readonly"';?> />
      </td>
    </tr>
    <tr>
      <td align="right" class="key"><label for="code bar"> <?php echo JText::_( 'CVR-nr' ); ?>: </label>
      </td>
      <td><input class="text_area" type="text" name="cvr" id="cvr" size="50" maxlength="250" value="<?php echo $this->user->cvr;?>" <?php if($this->product->id) echo 'readonly="readonly"';?> />
      </td>
    </tr>
    <tr>
      <td align="right" class="key"><label for="code bar"> <?php echo JText::_( 'Address' ); ?>:* </label>
      </td>
      <td><input class="text_area" type="text" name="address" id="address" size="50" maxlength="250" value="<?php echo $this->user->address;?>" <?php if($this->product->id) echo 'readonly="readonly"';?> />
      </td>
    </tr>
     <tr>
      <td align="right" class="key"><label for="code bar"> <?php echo JText::_( 'Postnr.' ); ?>:* </label>
      </td>
      <td><input class="text_area" type="text" name="code" id="code" size="20" maxlength="4" value="<?php echo $this->user->code;?>" <?php if($this->product->id) echo 'readonly="readonly"';?> />
      </td>
    </tr>
     <tr>
      <td align="right" class="key"><label for="code bar"> <?php echo JText::_( 'City' ); ?>:* </label>
      </td>
      <td><input class="text_area" type="text" name="city" id="city" size="50" maxlength="250" value="<?php echo $this->user->city;?>" <?php if($this->product->id) echo 'readonly="readonly"';?> />
      </td>
    </tr>
     <tr>
      <td align="right" class="key"><label for="code bar"> <?php echo JText::_( 'Phone' ); ?>: </label>
      </td>
      <td><input class="text_area" type="text" name="phone" id="phone" size="50" maxlength="250" value="<?php echo $this->user->phone;?>" <?php if($this->product->id) echo 'readonly="readonly"';?> />
      </td>
    </tr>
  </table>
  <br /><br />
  
  
  <table class="admintable">
  	   
    <tr>
      <td align="right" class="key">Product image:</td>
      <td><?php  
	  	if(trim($this->product->image)):
	  ?>
      	<?php echo "<img src='".JURI::root(false)."thumbnail/timthumb.php?src=".JURI::root(false)."components/com_ecommerce/imgupload/".$this->product->image."&w=150&zc=1' title='".$this->product->model."' alt='".$this->product->model ."' align='middle' />";?>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		<a href="<?php echo $link;?>"><img src="images/publish_x.png" align="absmiddle" />Delete</a>
		<?php endif;?>
		<input type="hidden" name="image" value="<?php echo $this->product->image; ?>" /></td>
    </tr>
    <tr>
      <td align="right" class="key"><label for="imagefile"> <?php echo JText::_( 'Upload Image ' ); ?>: </label>
      </td>
      <td><input type="file" name="txtimage" id="txtimage" size="32"  value="" />
      </td>
    </tr>
    
    <tr>
      <td align="right" class="key">Product image 1:</td>
      <td><?php  
	  	if(trim($this->product->image1)):
	  ?>
        <?php echo "<img src='".JURI::root(false)."thumbnail/timthumb.php?src=".JURI::root(false)."components/com_ecommerce/imgupload/".$this->product->image1."&w=150&zc=1' title='".$this->product->model."' alt='".$this->product->model ."' align='middle' />";?>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		<a href="<?php echo $link.'&hinh=1';?>"><img src="images/publish_x.png" align="absmiddle" />Delete</a>
		<?php endif;?>
		<input type="hidden" name="image1" value="<?php echo $this->product->image1; ?>" /></td>
    </tr>
    <tr>
      <td align="right" class="key"><label for="imagefile"> <?php echo JText::_( 'Upload Image 1' ); ?>: </label>
      </td>
      <td><input type="file" name="txtimage1" id="txtimage1" size="32"  value="" />
      </td>
    </tr>
    
    <tr>
      <td align="right" class="key">Product image 2:</td>
      <td><?php  
	  	if(trim($this->product->image2)):
	  ?>
        <?php echo "<img src='".JURI::root(false)."thumbnail/timthumb.php?src=".JURI::root(false)."components/com_ecommerce/imgupload/".$this->product->image2."&w=150&zc=1' title='".$this->product->model."' alt='".$this->product->model ."' align='middle' />";?>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		<a href="<?php echo $link.'&hinh=2';?>"><img src="images/publish_x.png" align="absmiddle" />Delete</a>
		<?php endif;?>
		<input type="hidden" name="image2" value="<?php echo $this->product->image2; ?>" /></td>
    </tr>
    <tr>
      <td align="right" class="key"><label for="imagefile"> <?php echo JText::_( 'Upload Image 2' ); ?>: </label>
      </td>
      <td><input type="file" name="txtimage2" id="txtimage2" size="32"  value="" />
      </td>
    </tr>
    
    <tr>
      <td align="right" class="key">Product image 3:</td>
      <td><?php  
	  	if(trim($this->product->image3)):
	  ?>
      	<?php echo "<img src='".JURI::root(false)."thumbnail/timthumb.php?src=".JURI::root(false)."components/com_ecommerce/imgupload/".$this->product->image3."&w=150&zc=1' title='".$this->product->model."' alt='".$this->product->model ."' align='middle' />";?>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		<a href="<?php echo $link.'&hinh=3';?>"><img src="images/publish_x.png" align="absmiddle" />Delete</a>
		<?php endif;?>
		<input type="hidden" name="image3" value="<?php echo $this->product->image3; ?>" /></td>
    </tr>
    <tr>
      <td align="right" class="key"><label for="imagefile"> <?php echo JText::_( 'Upload Image 3' ); ?>: </label>
      </td>
      <td><input type="file" name="txtimage3" id="txtimage3" size="32"  value="" />
      </td>
    </tr>
    
    <tr>
      <td align="right" class="key">Product image 4:</td>
      <td><?php  
	  	if(trim($this->product->image4)):
	  ?>
        <?php echo "<img src='".JURI::root(false)."thumbnail/timthumb.php?src=".JURI::root(false)."components/com_ecommerce/imgupload/".$this->product->image4."&w=150&zc=1' title='".$this->product->model."' alt='".$this->product->model ."' align='middle' />";?>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		<a href="<?php echo $link.'&hinh=4';?>"><img src="images/publish_x.png" align="absmiddle" />Delete</a>
		<?php endif;?>
		<input type="hidden" name="image4" value="<?php echo $this->product->image4; ?>" /></td>
    </tr>
    <tr>
      <td align="right" class="key"><label for="imagefile"> <?php echo JText::_( 'Upload Image 4' ); ?>: </label>
      </td>
      <td><input type="file" name="txtimage4" id="txtimage4" size="32"  value="" />
      </td>
    </tr>
    
    <?php
	$i = 0;
	if($this->images){
	foreach($this->images as $image){
		$stt = $i + 5;
	?>
     <tr>
      <td align="right" class="key">Product image <?php echo $stt;?>:</td>
      <td>
        <?php echo "<img src='".JURI::root(false)."thumbnail/timthumb.php?src=".JURI::root(false)."components/com_ecommerce/imgupload/".$image->name."&w=150&zc=1' title='".$this->product->model."' alt='".$this->product->model ."' align='middle' />";?>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		<a href="<?php echo $link1.'&name='.$image->name.'&id='.$this->product->id;?>"><img src="images/publish_x.png" align="absmiddle" />Delete</a>
		<input type="hidden" name="imageold<?php echo $i;?>" value="<?php echo $image->name; ?>" /></td>
    </tr>
    <tr>
      <td align="right" class="key"><label for="imagefile"> <?php echo JText::_( 'Upload Image '.$stt ); ?>: </label>
      </td>
      <td><input type="file" name="imageadd<?php echo $i;?>" id="imageadd<?php echo $i;?>" size="32"  value="" />
      </td>
    </tr>
    <?php $i++;}
	}
	?>
    <input type="hidden" id="imageNum" name="imageNum" value="<?php echo $i;?>" />
    <div id="moreField"></div>
    <tr><td colspan="2"><img src="../templates/tpl_automobil/images/btn_more_upload.jpg" class="moreUpload" style="cursor:pointer;" /></td></tr>
    </table>
  </fieldset>
  <fieldset class="adminform">
  	<legend><?php echo JText::_( 'Udstyr & dæk' ); ?></legend>
    <div class="admintable" style="float:left; width:450px;">
    	<?php echo $this->loadTemplate('leftStep2');?>
    </div>
    <div class="admintable" style="width:450px; margin-left:20px; float:left;">
    	<?php echo $this->loadTemplate('rightStep2');?>
    </div>   
  </fieldset>
  <fieldset class="adminform">
  	<legend><?php echo JText::_( 'Indvendig og udvendig stand' ); ?></legend>
     <div class="admintable" style="float:left; width:450px;">
    	<?php echo $this->loadTemplate('leftStep3');?>
    </div>
    <div class="admintable" style="width:450px; margin-left:20px; float:left;">
    	<?php echo $this->loadTemplate('rightStep3');?>
    </div>
  </fieldset>
  <fieldset class="adminform">
  	<legend><?php echo JText::_( 'Tidligere skader & vedligeholdelse' ); ?></legend>
    <div class="admintable" style="float:left; width:450px;">
    	<?php echo $this->loadTemplate('leftStep4');?>
    </div>
    <div class="admintable" style="width:450px; margin-left:20px; float:left;">
    	<?php echo $this->loadTemplate('rightStep4');?>
    </div>
  </fieldset>
  </div>
  <div class="clr"></div>
  <input type="hidden" name="option" value="com_ecommerce" />
  <input type="hidden" name="id" value="<?php echo $this->product->id; ?>" />
  <input type="hidden" name="user_id" value="<?php echo $this->product->user_id; ?>" id="user_id" />
  <input type="hidden" name="approve" value="<?php echo $this->product->approve; ?>" />
  <input type="hidden" name="bought" value="<?php echo $this->product->bought; ?>" />
  <input type="hidden" name="ordering" value="<?php echo $this->product->ordering; ?>" />
  <input type="hidden" name="published" value="1" />
  <input type="hidden" name="task" id="task" value="" />
  <input type="hidden" name="controller" value="registers" />
</form>
